<?php

namespace yak\layui\widgets\form;

use yii\base\Widget;

/**
 * Class IconPicker
 * @package yak\layui\widgets\form
 */
class AuthTree extends Widget
{
    /**
     * @var array
     */
    public $list = [];

    /**
     * @var
     */
    public $dst;

    /**
     * @var string
     */
    public $inputName = 'authids';

    /**
     * @var array
     */
    public $checkedId = [];

    public function run()
    {
        $json = json_encode($this->list);
        $checkedKey = json_encode($this->checkedId);
        $this->getView()->registerJs("layui.use(['authtree'],function(){var authTree=layui.authtree;trees=authTree.listConvert({$json},{primaryKey:'alias',startPid:0,parentKey:'palias',nameKey:'name',valueKey:'id',checkedKey:" . $checkedKey . "});authTree.render('{$this->dst}',trees,{inputname:'{$this->inputName}[]',layfilter:'lay-check-auth',autowidth:true,})});", 3);
    }
}